package com.lzq.his.controller;

import com.lzq.his.common.CommonResp;
import com.lzq.his.domain.Student;
import com.lzq.his.req.StudentReq;
import com.lzq.his.resp.PageResp;
import com.lzq.his.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping
    public  CommonResp<PageResp<Student>> selectAll(StudentReq req) {
        System.out.println(req);
        CommonResp resp = new CommonResp();
        PageResp<Student> students = studentService.selectAll(req);
        resp.setContent(students);
        return resp;
    }

    @PostMapping("/save")
    public void save(@RequestBody Student Student) {
        System.out.println(Student);
        studentService.save(Student);
    }

    @PostMapping("/save2")
    public CommonResp save2(@RequestBody Student Student) {
        System.out.println(Student);
        CommonResp commonResp = studentService.save2(Student);
        return commonResp;
    }

    @DeleteMapping("/delete/{id}")
    public void deletestudent(@PathVariable String id) {
        studentService.deleteById(id);
    }

    @GetMapping("/select-max-id")
    public int selectId() {
        return studentService.maxid();
    }
}
